<template>
  <div class="history-date">
    <span style="font-size: 12px; color: #7d7d7d; font-weight: bold">{{
      dateLabel
    }}</span>
    <div class="history-content">
      <div class="content" v-for="item in items" :key="item.chatHistoryId">
        <input
          :ref="'inputField' + item.chatHistoryId"
          :disabled="isDisabled"
          @keyup.enter="confirmInput(item)"
          @blur="confirmInput(item)"
          class="info"
          v-model="item.chatTitle"
        />
        <div class="option-btn" @click.stop="toggleMenu($event, item)">
          <el-tooltip content="选项" placement="top">
            <img
              class="option-btn"
              src="../../assets/img/no-active.png"
              draggable="false"
              style="width: 18.8px; height: 18.8px"
            />
          </el-tooltip>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    dateLabel: String,
    items: Array,
    isDisabled: Boolean,
  },
  methods: {
    confirmInput(item) {
      this.$emit("confirmInput", item);
    },
    toggleMenu(event, item) {
      this.$emit("toggleMenu", event, item);
    },
    focusInput(chatHistoryId) {
      const refInput = "inputField" + chatHistoryId;
      this.$nextTick(() => {
        if (this.$refs[refInput] && this.$refs[refInput][0].focus) {
          this.$refs[refInput][0].focus();
        }
      });
    },
  },
};
</script>

<style lang="less">
.history-date {
  .history-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
    height: 100%;
    .content {
      padding: 7px;
      border-radius: 10px;
      position: relative;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .info {
        font-size: 14px;
        border: none;
        background-color: transparent;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        width: 180px;
      }
      .info:focus {
        border: none;
        outline: none;
        border-bottom: 1px solid #ccc;
      }
      .info {
        color: black;
      }
      .option-btn {
        display: none;
      }
    }
    .content:hover {
      background-color: #e8e4e4;
      .option-btn {
        display: block;
      }
    }
  }
}
</style>
